package com.cxhc.app.api;

import com.cxhc.app.api.mapper.CmAreaInfoMapStructMapper;
import com.cxhc.app.api.vo.CmAreaInfoVo;
import com.cxhc.common.annotation.Anonymous;
import com.cxhc.common.core.domain.R;
import com.cxhc.system.domain.app.CmAreaInfo;
import com.cxhc.system.service.app.ICmAreaInfoService;
import com.github.pagehelper.PageHelper;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;

import com.cxhc.common.core.page.TableDataInfo;

import java.util.List;
import java.util.Map;

/**
 * 楼宇信息Controller
 * 
 * @author Dhq
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/api/CmAreaInfo")
public class ApiCmAreaInfo extends BaseController
{
    @Autowired
    private ICmAreaInfoService cmAreaInfoService;

    /**
     * 查询楼宇信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody CmAreaInfoVo cmAreaInfoVo)
    {
        PageHelper.startPage(cmAreaInfoVo.getPageNum(),cmAreaInfoVo.getPageSize());
        CmAreaInfo cmAreaInfo = CmAreaInfoMapStructMapper.INSTANCE.CmAreaInfoVoToCmAreaInfo(cmAreaInfoVo);
        List<CmAreaInfo> list = cmAreaInfoService.selectCmAreaInfoList(cmAreaInfo);
        return getDataTable(list);
    }

    /**
     * 查询楼宇信息列表
     */
    @PostMapping("/listForCockpit")
    @ResponseBody
    public TableDataInfo listForCockpit()
    {
        return getDataTable(cmAreaInfoService.selectCmAreaInfoListForCockpit());
    }


    /**
     * 获取楼宇信息详细信息
     */
    @GetMapping(value = "/details/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(cmAreaInfoService.selectCmAreaInfoByID(ID));
    }

    /**
     * 新增楼宇信息
     */
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody CmAreaInfoVo cmAreaInfoVo)
    {
        CmAreaInfo cmAreaInfo = CmAreaInfoMapStructMapper.INSTANCE.CmAreaInfoVoToCmAreaInfo(cmAreaInfoVo);
        return toAjax(cmAreaInfoService.insertCmAreaInfo(cmAreaInfo));
    }

    /**
     * 修改楼宇信息
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody CmAreaInfoVo cmAreaInfoVo)
    {
        CmAreaInfo cmAreaInfo = CmAreaInfoMapStructMapper.INSTANCE.CmAreaInfoVoToCmAreaInfo(cmAreaInfoVo);

        return toAjax(cmAreaInfoService.updateCmAreaInfo(cmAreaInfo));
    }

    /**
     * 删除楼宇信息
     */
	@GetMapping("/selete/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(cmAreaInfoService.deleteCmAreaInfoByIDs(IDs));
    }


    /**
     * 楼宇企业行业分布
     */
    @Anonymous
    @SneakyThrows
    @RequestMapping("/queryEntTypeForArea/{id}")
    public R<Map<String,String>> queryEntByTyp(@PathVariable String id) {
        return R.ok(cmAreaInfoService.queryEntByTyp(id));
    }

    /**
     * 楼宇企业人员统计
     */
    @Anonymous
    @SneakyThrows
    @RequestMapping("/queryUserCountForArea/{id}")
    public R<Map<String, Map<String, String>>> queryUserCountForArea(@PathVariable String id) {
        return R.ok(cmAreaInfoService.queryUserCountForArea(id));
    }
}
